#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>


using namespace std;


int GetMonth(int year, int month)
{
    int a[] = { 0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 };
    if (month == 2 && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)))
        a[month] = 29;
    return a[month];
}


int main() {
    int m;
    cin >> m;
    for (int i = 0; i < m; i++)
    {
        int year, month, day, n;
        cin >> year >> month >> day >> n;
        day += n;
        while (day > GetMonth(year, month))
        {
            day -= GetMonth(year, month);
            month++;
            if (month > 12)
            {
                month = 1;
                year++;
            }
        }
        printf("%d-%02d-%02d\n", year, month, day);
    }
    return 0;
}